package Youtube.actions;

import java.util.Comparator;
import java.util.Map;

import Main.Main;

public class ActivitiesComparator implements Comparator<String> {
	
	private Map<String, Double> unsortedMap;
	
	public ActivitiesComparator(Map<String, Double> unsortedMap) {
		  this.unsortedMap = unsortedMap;
		 }
	
	@Override
	 public int compare(String a, String b) {
	  if (unsortedMap.get(a) > unsortedMap.get(b)) {
	   /* System.out.println(a +" e' prima di "+b);*/
	   return -1;
	  } else if ((unsortedMap.get(a) < unsortedMap.get(b)))  {
	   // System.out.println(a +" e' dopo di "+b);
	   return 1;
	  } else {
		  //return a.compareTo(b);
		  return compare2String(a,b);
	  }
	 
	 }

	public int compare2String(String a, String b) {
		if (Main.video2Activity.get(a) > Main.video2Activity.get(b)) {
			return -1;
		} else if (Main.video2Activity.get(a) < Main.video2Activity.get(b)) {
			return 1;
		} else {
			return a.compareTo(b);
		}
	}

}
